home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSXT_SCH.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-29  |  3KB  |  113 lines

  1. unit GSXT_Sch;
  2. {------------------------------------------------------------------------------
  3.                                DBase Filters
  4.  
  5.        Copyright (c)  Richard F. Griffin
  6.  
  7.        19 July 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        A unit for rapidly searching dBase Record Fields for a string.
  14.  
  15.        Procedure is called as follows:
  16.  
  17.           Result := SearchDBF(s, FNum, fromtop)
  18.  
  19.        Where:
  20.               s          = The string to search for
  21.               FNum       = The record field to search
  22.               fromtop    = Boolean true to start from the top of the file,
  23.                            false to continue from the current record.
  24.               Result     = Starting position of the found string in the
  25.                            field, or zero if the string is not found.
  26.  
  27.        The file in the selected file (using GSOBShel) will be searched for
  28.        the record field that matches the string s.  Records will be read
  29.        through whatever filters are set (deleted records ignored, etc.).
  30.        When a match is found the starting location within the field is
  31.        returned and the file is positioned with the matching record as
  32.        the current record.  If no match, zero is returned and the current
  33.        record is positioned to the initial position as when the call was
  34.        made.
  35.  
  36.        NOTE THAT THIS TEST IS NOT CASE SENSITIVE!!
  37.  
  38.        See TESTSCH1.PAS and TESTSCH2.PAS for an example of how to use the
  39.        routine.
  40.  
  41. -------------------------------------------------------------------------------}
  42.  
  43. interface
  44. uses GSOB_Str, GSOBShel, GSOB_DBF, GSOB_Var;
  45.  
  46. Function SearchDBF(s : string; var FNum : word; fromtop: boolean): word;
  47.  
  48. implementation
  49.  
  50. Function SearchDBF(s : string; var FNum : word; fromtop: boolean): word;
  51. var
  52.    BTable: string;
  53.    MTable: string;
  54.    crd : boolean;
  55.    ia : pointer;
  56.    lr : longint;
  57.    sloc: word;
  58.    i   : integer;
  59.    Strt: word;
  60.    Size: word;
  61.    rnum: longint;
  62. begin
  63.    if (FNum = 0) or (FNum > FieldCount) then
  64.    begin
  65.       SearchDBF := 0;
  66.       exit;
  67.    end;
  68.    BTable := AllCaps(s);
  69.    with DBFActive^ do
  70.    begin
  71.       StatusUpdate(StatusStart,StatusSearch,NumRecs);
  72.       lr := RecNo;
  73.       ia := IndexMaster;
  74.       IndexMaster := nil;
  75.       crd := CacheRead;
  76.       SetDBFCache(On);
  77.  
  78.       Strt := 1;
  79.       if FNum > 1 then
  80.          for i := 1 to FNum-1 do
  81.             Strt := Strt + FieldLen(i);
  82.       Size := FieldLen(FNum);
  83.  
  84.       if fromtop then GoTop else Skip(1);
  85.       rnum := RecNo;
  86.       sloc := 0;
  87.  
  88.       while not File_EOF and (sloc = 0) do
  89.       begin
  90.          move(CurRecord^[Strt],MTable[1],Size);
  91.          MTable[0] := chr(Size);
  92.          MTable := AllCaps(MTable);
  93.          sloc := pos(BTable,MTable);
  94.          if sloc = 0 then
  95.          begin
  96.             inc(rnum);
  97.             StatusUpdate(StatusSearch,rnum,0);
  98.             GetRec(rnum);
  99.          end;
  100.       end;
  101.       SetDBFCache(crd);
  102.       IndexMaster := ia;
  103.       if sloc > 0 then
  104.          Go(rnum)            {Reset for index}
  105.       else
  106.          GO(lr);
  107.       SearchDBF := sloc;
  108.       StatusUpdate(StatusStop,0,0);
  109.    end;
  110. end;
  111.  
  112. end.
  113.